package org.vm.cmbcdirect.wechat.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.vm.cmbcdirect.utils.HttpUtil;
import org.vm.cmbcdirect.wechat.listener.MainListener;

/**
 * Created by mv on 2016/3/22.
 */
@Controller
public class MenuController {
    @RequestMapping(value="addMenu", method= RequestMethod.GET)
    @ResponseBody
    public String editMenu(Model model, @ModelAttribute("menuContent") String menuContent) {

        String delUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + MainListener.getAccessToken().getToken();
        HttpUtil.httpRequest(delUrl, "GET", null);

        String menuContents = "{\n" +
                "     \"button\":[\n" +
                "     {\n" +
                "           \"name\":\"1\",\n" +
                "           \"sub_button\":[\n" +
                "           {    \n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"来唠嗑 \",\n" +
                "               \"key\":\"11\"\n" +
                "            },\n" +
                "            {\n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"1.2\",\n" +
                "               \"key\":\"12\"\n" +
                "            }]\n" +
                "       },\n" +
                "      {\n" +
                "           \"name\":\"2 \",\n" +
                "           \"sub_button\":[\n" +
                "           {\n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"2.1\",\n" +
                "               \"key\":\"21\"\n" +
                "            },\n" +
                "            {\n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"2.2\",\n" +
                "               \"key\":\"22\"\n" +
                "            },\n" +
                "            {\n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"2.3\",\n" +
                "               \"key\":\"23\"\n" +
                "            }]\n" +
                "       },\n" +
                "      {\n" +
                "           \"name\":\"3 \",\n" +
                "           \"sub_button\":[\n" +
                "            {\n" +
                "               \"type\":\"click\",\n" +
                "               \"name\":\"3.1\",\n" +
                "               \"key\":\"31\"\n" +
                "            }]\n" +
                "       }]\n" +
                " }";
        ;

        System.out.println(menuContents);
        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + MainListener.getAccessToken().getToken();
        HttpUtil.httpRequest(url, "POST", menuContents);

        return "";
    }
}
